//
//  threelevelViewController.m
//  BAOASystem
//
//  Created by michael on 2018/1/29.
//  Copyright © 2018年 czd. All rights reserved.
//
#import "shangpinlistViewController.h"
#import "threelevelViewController.h"
#import "SkyAssociationMenuView.h"
#import "zhaocanpinViewController.h"
@interface threelevelViewController ()<SkyAssociationMenuViewDelegate>
@property (strong, nonatomic) SkyAssociationMenuView *v;

@end

@implementation threelevelViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = NSLocalizedString(@"全部分类", nil);
    self.view.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
    
    _array = @[@"农林牧渔",@"机械五金",@"纺织业",@"制造业",@"矿业",@"建筑业",@"商贸流通",@"交通运输、仓储和邮政业", @"住宿和餐饮业",@"金融通讯商务服务",@"地产业",@"租赁和商务服务",@"科研和技术服务",@"其他服务业"];
    [self loadata];
    
    // Do any additional setup after loading the view.
}
-  (void)loadata{

 NSMutableDictionary *dics=[NSMutableDictionary dictionary];
      dics[@"userName"] = @"administrator";
    dics[@"password"] = @"b628e2c3b78ef9bf269c489b35176e48";
    
    dics[@"language"] = [[NSUserDefaults standardUserDefaults] objectForKey:@"language"];
    
     dics[@"website"] = [[NSUserDefaults standardUserDefaults] objectForKey:@"website"];
        dics[@"type"] = BAtype;
        if([_type isEqualToString:@"shangpin"]){
              dics[@"selOneCategory"] = @"0";
        dics[@"selTwoCategory"] = @"0";
        }else if([_type isEqualToString:@"qiye"]){
              dics[@"selOneCategory"] = @"0";
        dics[@"selTwoCategory"] = @"1";
        }else{
        dics[@"selOneCategory"] = @"1";
        dics[@"selTwoCategory"] = @"1";
        }
  
          [MBProgressHUD showHUDAddedTo:self.view animated:YES];

NSString *dicstring = [httpTool dictionaryToJson:dics];

dicstring= [dicstring URLEncodedString];
NSString *url = [[NSString alloc]initWithFormat:@"%@/api/commonApi/oneLevelCategoryList?data=%@",BAip,dicstring];
 [httpTool ZBPostNetDataWith:url withDic:nil andSuccess:^(NSDictionary* dictionary){
  [MBProgressHUD hideHUDForView:self.view animated:YES];
  _dic = dictionary;
      _v = [SkyAssociationMenuView new];

   _v.array = _array;
  _v.dic = _dic;
   _v.delegate = self;
   
    [self.view addSubview:_v];
  NSLog(@"%@",dictionary);
 }andFailure:^{
  [MBProgressHUD hideHUDForView:self.view animated:YES];

//         [self.tableView headerEndRefreshing];

 }];
}
- (NSInteger)assciationMenuView:(SkyAssociationMenuView*)asView countForClass:(NSInteger)idx {
    NSLog(@"choose %ld", idx);
    return _array.count;
}

- (NSString*)assciationMenuView:(SkyAssociationMenuView*)asView titleForClass_1:(NSInteger)idx_1 {
    NSLog(@"title %ld", idx_1);
    return [NSString stringWithFormat:@"title %ld", idx_1];
}

- (NSString*)assciationMenuView:(SkyAssociationMenuView*)asView titleForClass_1:(NSInteger)idx_1 class_2:(NSInteger)idx_2 {
    NSLog(@"title %ld, %ld", idx_1, idx_2);
//  NSArray *array = _dic[@"oneLevelCategoryList"];
//NSDictionary *dic = array[idx_1];
//NSArray *array2 = dic[@"twoLevelCategoryList"];
//NSDictionary *dic2 = array2[idx_2];
//if ([[NSString stringWithFormat:@"%@",dic2[@"showIndex"]]isEqualToString:@"101"]) {
//
//shangpinlistViewController *vc = [[shangpinlistViewController alloc]init];
//
//vc.hidesBottomBarWhenPushed = YES;
//vc.ctgid = dic2[@"id"];
//    [self.navigationController pushViewController:vc animated:YES];
//    }
    return [NSString stringWithFormat:@"title %ld, %ld", idx_1, idx_2];
}
- (BOOL)assciationMenuView:(SkyAssociationMenuView*)asView idxChooseInClass1:(NSInteger)idx_1 class2:(NSInteger)idx_2;
{
     NSArray *array = _dic[@"oneLevelCategoryList"];
NSDictionary *dic = array[idx_1];
NSArray *array2 = dic[@"twoLevelCategoryList"];
NSDictionary *dic2 = array2[idx_2];

//ctgName
if ([[NSString stringWithFormat:@"%@",dic2[@"showIndex"]]isEqualToString:@"101"]) {

shangpinlistViewController *vc = [[shangpinlistViewController alloc]init];

vc.hidesBottomBarWhenPushed = YES;
vc.ctgid = dic2[@"id"];
    [self.navigationController pushViewController:vc animated:YES];
//    }
    return YES;

}else{
    return YES;


}
// return YES;
}

- (BOOL)assciationMenuView:(SkyAssociationMenuView*)asView idxChooseInClass1:(NSInteger)idx_1 class2:(NSInteger)idx_2 class3:(NSInteger)idx_3{
  NSArray *array = _dic[@"oneLevelCategoryList"];
NSDictionary *dic = array[idx_1];
NSArray *array2 = dic[@"twoLevelCategoryList"];
NSDictionary *dic2 = array2[idx_2];
NSArray *array3 = dic2[@"threeLevelCategoryList"];
NSMutableArray *arraytitle3 = [NSMutableArray array];
 for (NSDictionary *dic in array3) {
    [arraytitle3 addObject:dic[@"id"]];
}
NSDictionary *dic3 = array3[idx_3];
NSString *string =arraytitle3[idx_3];
shangpinlistViewController *vc = [[shangpinlistViewController alloc]init];

vc.hidesBottomBarWhenPushed = YES;
vc.ctgid = string;
if([_type isEqualToString:@"shangpin"]){
 if (self.selectRowBlock) {
        self.selectRowBlock(dic3[@"ctgName"], string);
    }
[self.navigationController popViewControllerAnimated:YES];
}else if([_type isEqualToString:@"qiye"]){
 if (self.selectRowBlock) {
        self.selectRowBlock(dic3[@"ctgName"], string);
    }
[self.navigationController popViewControllerAnimated:YES];
}
else{
[self.navigationController pushViewController:vc animated:YES];

}

 
   
       return YES;
}
- (NSString*)assciationMenuView:(SkyAssociationMenuView*)asView titleForClass_1:(NSInteger)idx_1 class_2:(NSInteger)idx_2 class_3:(NSInteger)idx_3 {
   
    NSLog(@"title %ld, %ld, %ld", idx_1, idx_2, idx_3);
    return [NSString stringWithFormat:@"%ld,%ld,%ld", idx_1, idx_2, idx_3];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
